package edu.nanyang.struts;

import java.util.List;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;

import edu.nanyang.domain.Replys;
import edu.nanyang.domain.User;
import edu.nanyang.hibernate.service.IReplysService;
import edu.nanyang.util.ReplysHelper;


public class ReplysAction extends ActionSupport {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private IReplysService replysService;
	private int goodsId;
	private double price;
	private String replyWords;
	private String result;
	private boolean resultBoolean;
	private List<ReplysHelper> replyHelpers;
	public String addReply(){
		Object o=ServletActionContext.getRequest().getSession().getAttribute("user");
		if(o==null){
			result="回复失败,您尚未登录";
			resultBoolean=false;
			return SUCCESS;
		}
		if(goodsId==0){
			result="回复失败,找不到对应商品";
			resultBoolean=false;
			return SUCCESS;
		}
		Replys r=new Replys();
		r.setGoodsId(goodsId);
		r.setPrice(price);
		r.setReplyWords(replyWords);
		r.setUserId(((User)o).getId());
		if(this.replysService.addReplys(r)){
			result="回复成功";
			resultBoolean=true;
		}else{
			result="回复失败,请联系管理员";
			resultBoolean=false;
		}
		return SUCCESS;
	}
	public String acquireReplysByGoodsId(){
		replyHelpers=this.replysService.getReplysByGoodsId(goodsId);
		return SUCCESS;
	}
	public void setReplysService(IReplysService replysService) {
		this.replysService = replysService;
	}
	public int getGoodsId() {
		return goodsId;
	}
	public void setGoodsId(int goodsId) {
		this.goodsId = goodsId;
	}
	public double getPrice() {
		return price;
	}
	public void setPrice(double price) {
		this.price = price;
	}
	public String getReplyWords() {
		return replyWords;
	}
	public void setReplyWords(String replyWords) {
		this.replyWords = replyWords;
	}
	public String getResult() {
		return result;
	}
	public void setResult(String result) {
		this.result = result;
	}
	public boolean isResultBoolean() {
		return resultBoolean;
	}
	public void setResultBoolean(boolean resultBoolean) {
		this.resultBoolean = resultBoolean;
	}
	public List<ReplysHelper> getReplyHelpers() {
		return replyHelpers;
	}
	public void setReplyHelpers(List<ReplysHelper> replyHelpers) {
		this.replyHelpers = replyHelpers;
	}
	
}
